#pragma once

#include <WinError.h>
#include <xstring>          // basic_string
#include "atlstr.h"         // CString
#include "comutil.h"		// _bstr_t / _variant_t -- Need link comsuppw.lib
#include "math.h"
#include "Constants.h"
using namespace std;

//#include <vcclr.h>       // System::String
//using namespace System;

class DLLEXPIMP TypeConvert
{
public:
	// Converting from char *
	static bool charTowchar_t(char* pszIn, wchar_t* pszOut);

	// Converting from wchar_t *
	static bool wchar_tTochar(wchar_t* pszIn, char* pszOut);

	// Converting from CString
	static bool cstringTochar(CString strIn, char* pszOut);
	static bool cstringTowchar_t(CString strIn, wchar_t* pszOut);
	static bool cstringTo_bstr_t(CString strIn, _bstr_t& bstrOut);

	// Converting from basic_string
	static bool stringTochar(string strIn, char* pszOut);
	static bool stringTowchar_t(string strIn, wchar_t* pszOut);
	static bool stringTocstring(string strIn, CString& strOut);
	static bool stringTo_bstr_t(string strIn, _bstr_t& bstrOut);

	// Converting from _bstr_t
	static bool _bstr_tTostring(_bstr_t bstrIn, string& strOut);
	static bool _bstr_tTochar(_bstr_t bstrIn, char* pszOut);
	static bool _bstr_tTowchar_t(_bstr_t bstrIn, wchar_t* pszOut);
	static bool _bstr_tTocstring(_bstr_t bstrIn, CString& cstrOut);

	// system::String to the other string types
	//ErrorStatus StringTochar(String^ strIn, char* pszOut);
	//ErrorStatus StringTowchar_t(String^ strIn, wchar_t* pszOut);

	// -----------------------------------------------------------------------------------------
	// Native Data Type --> String
	// -----------------------------------------------------------------------------------------
	static bool NativeToString( BYTE bValue, CString& string );
	static bool NativeToString( int iValue, CString& string );
	static bool NativeToString( UINT iValue, CString& string );
	static bool NativeToString( long lValue, CString& string );
	static bool NativeToString( ULONG lValue, CString& string );
	static bool NativeToString( float fValue, CString& string );
	static bool NativeToString( double dValue, CString& string );
	static bool NativeToString( bool bValue, CString& string );
	static bool NativeToString( LPGUID pGuid, CString& string );
	static bool NativeToString( CLSID clsid, CString& string );

	// -----------------------------------------------------------------------------------------
	// String --> Native Data Type
	// -----------------------------------------------------------------------------------------
	static bool StringToNative( const CString& string, BYTE* bValue );
	static bool StringToNative( const CString& string, int* iValue );
	static bool StringToNative( const CString& string, UINT* iValue );
	static bool StringToNative( const CString& string, long* lValue );
	static bool StringToNative( const CString& string, ULONG* ulValue );
	static bool StringToNative( const CString& string, float* fValue );
	static bool StringToNative( const CString& string, double* dValue );
	static bool StringToNative( const CString& string, bool* bValue );
};

